import helpers.FileHelper as FileHelper
import helpers.GUIHelper as GUIHelper



script_filter = FileHelper.SuffixFilter({"lua", "js", "json", "vert", "frag"})


def check(root_path):
    def callback(file_path, dirname, filename):
        lines = FileHelper.r_line(file_path)
        for row in range(len(lines)):
            line = lines[row]
            for col in range(len(line)):
                char = line[col]
                if ord(char) > 127:
                    info = "{}:{}:{}\n发现非ascii字符\nyes: skip\n no: ignore".format(filename, row + 1, col + 1)
                    if GUIHelper.ask_continue3("WARNING", info):
                        return True
    print("Checking non-ascii in script...")
    FileHelper.filter_dir(root_path, [script_filter], callback)

